using System;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Way.EntityDB.Attributes;
using System.Diagnostics.CodeAnalysis;

namespace DocumentBuilderServer.DBModels
{
    [TableConfig]
    [Table("category")]
    [Way.EntityDB.DataItemJsonConverter]
    public class Category :Way.EntityDB.DataItem
    {
        System.Nullable<Int64> _id;
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DisallowNull]
        [Column("id")]
        public virtual System.Nullable<Int64> id
        {
            get
            {
                return _id;
            }
            set
            {
                if ((_id != value))
                {
                    SendPropertyChanging("id",_id,value);
                    _id = value;
                    SendPropertyChanged("id");
                }
            }
        }
        string? _Caption;
        [MaxLength(50)]
        [Column("caption")]
        public virtual string? Caption
        {
            get
            {
                return _Caption;
            }
            set
            {
                if ((_Caption != value))
                {
                    SendPropertyChanging("Caption",_Caption,value);
                    _Caption = value;
                    SendPropertyChanged("Caption");
                }
            }
        }
        Int32 _Sort=0;
        [DisallowNull]
        [Column("sort")]
        public virtual Int32 Sort
        {
            get
            {
                return _Sort;
            }
            set
            {
                if ((_Sort != value))
                {
                    SendPropertyChanging("Sort",_Sort,value);
                    _Sort = value;
                    SendPropertyChanged("Sort");
                }
            }
        }
        /// <summary>把字段的更新，设置为一个指定的表达式值</summary>
        /// <param name="exp">指定的更新表达式，如 m=&gt;m.age == m.age + 1 &amp;&amp; name == name + "aa"，相当于sql语句的 age=age+1,name=name + 'aa'</param>
         public virtual void SetValue(System.Linq.Expressions.Expression<Func<Category, bool>> exp)
        {
            base.SetValue<Category>(exp);
        }
    }
    [TableConfig]
    [Table("doc")]
    [Way.EntityDB.DataItemJsonConverter]
    public class Doc :Way.EntityDB.DataItem
    {
        System.Nullable<Int64> _id;
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DisallowNull]
        [Column("id")]
        public virtual System.Nullable<Int64> id
        {
            get
            {
                return _id;
            }
            set
            {
                if ((_id != value))
                {
                    SendPropertyChanging("id",_id,value);
                    _id = value;
                    SendPropertyChanged("id");
                }
            }
        }
        System.Nullable<Int64> _CategoryId;
        [Column("categoryid")]
        public virtual System.Nullable<Int64> CategoryId
        {
            get
            {
                return _CategoryId;
            }
            set
            {
                if ((_CategoryId != value))
                {
                    SendPropertyChanging("CategoryId",_CategoryId,value);
                    _CategoryId = value;
                    SendPropertyChanged("CategoryId");
                }
            }
        }
        string? _Caption;
        [MaxLength(50)]
        [Column("caption")]
        public virtual string? Caption
        {
            get
            {
                return _Caption;
            }
            set
            {
                if ((_Caption != value))
                {
                    SendPropertyChanging("Caption",_Caption,value);
                    _Caption = value;
                    SendPropertyChanged("Caption");
                }
            }
        }
        Int32 _Sort=0;
        [DisallowNull]
        [Column("sort")]
        public virtual Int32 Sort
        {
            get
            {
                return _Sort;
            }
            set
            {
                if ((_Sort != value))
                {
                    SendPropertyChanging("Sort",_Sort,value);
                    _Sort = value;
                    SendPropertyChanged("Sort");
                }
            }
        }
        Int32 _Version=0;
        [DisallowNull]
        [Column("version")]
        public virtual Int32 Version
        {
            get
            {
                return _Version;
            }
            set
            {
                if ((_Version != value))
                {
                    SendPropertyChanging("Version",_Version,value);
                    _Version = value;
                    SendPropertyChanged("Version");
                }
            }
        }
        /// <summary>把字段的更新，设置为一个指定的表达式值</summary>
        /// <param name="exp">指定的更新表达式，如 m=&gt;m.age == m.age + 1 &amp;&amp; name == name + "aa"，相当于sql语句的 age=age+1,name=name + 'aa'</param>
         public virtual void SetValue(System.Linq.Expressions.Expression<Func<Doc, bool>> exp)
        {
            base.SetValue<Doc>(exp);
        }
    }
}

namespace DocumentBuilderServer.DBModels.DB
{
    public class Document : Way.EntityDB.DBContext
    {
         public Document(string connection, Way.EntityDB.DatabaseType dbType , bool upgradeDatabase = true): base(connection, dbType , upgradeDatabase)
        {
            if (!setEvented)
            {
                lock (lockObj)
                {
                    if (!setEvented)
                    {
                        setEvented = true;
                        Way.EntityDB.DBContext.BeforeDelete += Database_BeforeDelete;
                    }
                }
            }
        }
        static object lockObj = new object();
        static bool setEvented = false;
        static void Database_BeforeDelete(object sender, Way.EntityDB.DatabaseModifyEventArg e)
        {
             var db =  sender as Document;
            if (db == null) return;
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Category>().HasKey(m => m.id);
            modelBuilder.Entity<Doc>().HasKey(m => m.id);
        }
        System.Linq.IQueryable<Category> _Category;
        public virtual System.Linq.IQueryable<Category> Category
        {
            get
            {
                if (_Category == null)
                {
                    _Category = this.Set<Category>();
                }
                return _Category;
            }
        }
        System.Linq.IQueryable<Doc> _Doc;
        public virtual System.Linq.IQueryable<Doc> Doc
        {
            get
            {
                if (_Doc == null)
                {
                    _Doc = this.Set<Doc>();
                }
                return _Doc;
            }
        }
        protected override string GetDesignString()
        {
            var result = new StringBuilder();
            result.Append("\r\n");
            result.Append("H4sIAAAAAAAACuVY32/aMBD+X/xcJiCQhr51sEnRJlqNrppU+uAkB7VqbOY4Q6jif9/ZMSRdaQqMtqA+4fvh8/nzl7sTD+SKRhxScnbzkC/7dALkjAx+c6aBnJAfcpZbQw2TfOVcWILma8ozFBqLk5Vez6dQWEhXAdVgY5/HmklBSr6xFBqELrk/DPM8huQMlyzB32bz");
            result.Append("9GRIYjo1u1EWGeeoMCFQQn+mjT+qelTTiKYQ9tDgmV3su4zvUagvUOhKnk1EiuLNMnaj0/AqgxsvlMP0PNMyFLGCCSaMJq0yMDGp6OMWVIwoT40mia4QAbs5YmNmnFHrdC78F5FNejBioqTjIMb6rpATGNGMawtMobXg2PvlsITp5TcrunykSkDZq9WttcfSWLEJE1RL");
            result.Append("Vcqyy2maulu60Fb1FdclNb5VgVSrEqnu0rIWrtW5K7xcwiW4/lAV31G1LV5D0q7bPVsitkypgKyxd8jalZBdmJM3BmwNwXZg15Csw2pIcgi3AKu5F7BuTZTer64UIza2n2aucQT+mYIKLZaLct1I3IderkHeKQYz9WqgseDYT/6FqtWsqFp3VIy3qloXPFkV0H/KUh9m");
            result.Append("z5kEzEpVyVw9ticn62tVNZ0GUukPzSZUf6bxfTbNny+5VHIKSjMwOCKMztW8ljKlmfIiY/ctLhaWkglw0I9e4T2J6r1uew0qWdWT8e7N1T/a5hq8cXPdYMYx/Nq5ue4G1/rv+yW43qKzBkc/jARv0V/LkHWOt3u8gJV39LNI671mkS4mOJZqvvE4cnjtsf2q2C373xPk");
            result.Append("loYtZ7jqQr98jo9e6/9nlFs1y4Mc5vxDYmvBy2a9kpfXoNJtGuqBNYjW3hrEIRREFN1JxJAsX5epZmZ1A7P5J2+eIhs/hUL7LXvSI29HwKf+A62YGD/dULBw8z2PLvVsarfmWsY6AO021qnXjtpBqzYa+V6tVfcbtajZCGpRlPjQoQEEHZ8s/gIAqwvxxRQAAA==");
            return result.ToString();
        }
    }
}

/*<design>
H4sIAAAAAAAACtWWX2+bMBDAv0p1z6QCAowg7WEN60S3VZXSVZPGHgyY1KuxkYGqVZXvvnMcaNM2Wbp1XadIAd/5/vh3d8ANxKQlGWkoRDfACojGbyw4UfIHzdskhsix4JhUqIVY5l1FRQsWFNnpdY0y14JcilmrUF2gn71Gdiqnb1MoojQtsgb/Vlb7RZaCNuX8hLTn
aHCTqlTs7eFe1ER4PUKbNP3SUIV2aXpE8gt9NT71naK1XKr6VA46xguqZlRdUrVdcfBZFpSvWe/nTQpWn0XDqppTkwn+ULrAdNknmV9AFBgKs5rkd1GshdnvY6DZh06jBJuM/cwPvVFZBuORZwfOKHOdcJRlRUAnJKThJICFBWjXcdpA9M3UYOIP1CvCBDrsq6RLoiuU
NIdSh4aoJLyhFtREYUJabS++W3BKsrsOXRdtclK3TAqIRMf5EGBKWjqX6vqRIKvD2wur9xJu8oJEtjnoM0rE/aO6ntfr4lWeZoteag5X2IMBSq8h8iYWlJzM+9j63jWLIUXPX3MXPuLO872lO8fxNvvDjJP4ayIKerXMFtfxQUw5belUipLNB+FU8q4StydyJs54EybU
69q961qZiFzR5TxFreqwglMijnHvUNF+yCBjc7YcO7M2Dt+LroppycQg4VTM9WCZVUFL0vH2jPBu2LGOOWlOPuqFiS4VdpNO39aamDW5YhUTpJW3PTblpGnMSYzDpeAQb2+FfSGQgre55Yz0ERR9pJ6FSW5AcUlUfk7UzizAt+EpLFbhBxjOs8HwN8GYSdXuQuJ+Vzyl
JeABBNBcdmPgPhuD4NWPRfgCY/HLJ3FS/MZkPJHGw47YxuLvjUX4nzwjwpeYj8nrfkZsYTB+LgauvYnBGX4W7tgQ/wwDvvH+CAN+T+RaXCtZU9Uy8+Wx+AlB5g5xpQsAAA==
<design>*/

